package ch.evaleto.gwt.media.client.player.medias;

import java.util.HashMap;
import java.util.Map;


import ch.evaleto.gwt.media.client.player.Media;
import ch.evaleto.gwt.media.client.player.PlayerManager;

import com.google.gwt.user.client.ui.Image;

public class Generic implements Media {

	
	public enum WebContent{
		audio, xml, json, playlist
	}
	
	HashMap<String , Image> images=new HashMap<String, Image>();
	
	final String id;
	final String url;
	final String name;
	final String len;
	final String usertags;
	final String schedule;
	final String vote;
	final String comment;
	final String love;
	final Image image;
	Type type;
	
	public Generic(String url, String name, String id, String len, String schedule, String tags, String vote,String love, String comment, String image) {
		this.id=id;
		this.url=url;
		this.name=name;
		this.len=(len ==null || len.equals("-1") || len.equals(""))?"-1":len;
		this.schedule=schedule;
		this.usertags=tags;
		this.vote=vote;
		this.comment=comment;
		this.love=love;
		
		// be sure that image is not already used
		if (images.get(image)==null)
			images.put(image, new Image(image));
		this.image=images.get(image);
	}	
		
	public static Media decodeJson(String content){
		return null;
	}

	public int getDuration() {
		return Integer.parseInt(len);
	}

	public String getID() {
		return id;
	}

	public Image getImage() {
		return image;
	}

	public Map<String, String> getInformation() {
		return PlayerManager.get().details(this);
	}

	public String getName() {
		return name;
	}

	public String getScheduleURL() {
		return schedule;
	}

	public String getURL() {
		return url;
	}

	public String getUserTags() {
		return usertags;
	}

	public boolean isStream() {
		return len.equals("-1");
	}

	public Type getType() {
		return Type.unknown;
	}
	
	public String getComment(){
		return comment;
	}

	public String getLove(){
		return love;
	}
	public String getVote(){
		return vote;
	}
	
	public void free() {
		PlayerManager.get().free(this);
	}

	public boolean isPlaying() {
		return PlayerManager.get().playing(this);
	}

	public int position() {
		return PlayerManager.get().position(this);
	}

	public void position(int milliseconds) {
		PlayerManager.get().position(this,milliseconds);
	}
	


}
